package com.junzhiit.nengji.api.service.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bainaeco.framework.util.serializer.Format;
import com.junzhiit.nengji.api.service.ColumnService;
import com.junzhiit.nengji.api.service.GoodsHistoryService;
import com.junzhiit.nengji.api.web.exception.ColumnNotFoundException;
import com.junzhiit.nengji.api.web.util.Constants;
import com.junzhiit.nengji.api.web.vo.AdvertiseVO;
import com.junzhiit.nengji.api.web.vo.GoodsHistoryAEVO;
import com.junzhiit.nengji.api.web.vo.GoodsImagesVO;
import com.junzhiit.nengji.api.web.vo.ListVO;
import com.junzhiit.nengji.api.web.vo.ModulesAdvertiseVO;
import com.junzhiit.nengji.api.web.vo.ModulesGoodsVO;
import com.junzhiit.nengji.api.web.vo.ModulesShopVO;
import com.junzhiit.nengji.api.web.vo.ModulesVO;
import com.junzhiit.nengji.api.web.vo.ResultVO;
import com.junzhiit.nengji.api.web.vo.ShopModulesVO;
import com.junzhiit.nengji.bo.AdvertiseBO;
import com.junzhiit.nengji.bo.GoodsBO;
import com.junzhiit.nengji.bo.ModulesAdvertiseBO;
import com.junzhiit.nengji.bo.ModulesBO;
import com.junzhiit.nengji.bo.ModulesGoodsBO;
import com.junzhiit.nengji.bo.ShopModulesBO;
import com.junzhiit.nengji.dao.ColumnDAO;
import com.junzhiit.nengji.dao.GoodsDAO;
import com.junzhiit.nengji.dao.ModulesAdvertiseDAO;
import com.junzhiit.nengji.dao.ModulesDAO;
import com.junzhiit.nengji.dao.ModulesGoodsDAO;
import com.junzhiit.nengji.dao.ModulesShopsDAO;
import com.junzhiit.nengji.model.Column;
import com.junzhiit.nengji.model.enums.GoodsHistoryType;

@Service
public class ColumnServiceImpl extends BaseServiceImpl implements ColumnService {
	
	@Autowired
	private ModulesDAO modulesDAO;
	
	@Autowired
	private ColumnDAO columnDAO;
	
	@Autowired
	private ModulesGoodsDAO modulesGoodsDAO;
	
	@Autowired
	private ModulesAdvertiseDAO modulesAdvertiseDAO;
	
	@Autowired
	private GoodsHistoryService goodsHistoryService;
	
	@Autowired
	private ModulesShopsDAO modulesShopsDAO;
	
	@Autowired
	private GoodsDAO goodsDAO;
	
	@Override
	@Transactional
	public ResultVO findColumnInfo(String userId,String columnCode, String cityCode) {
		ResultVO result=new ResultVO();
		Map<String,Object> map = new HashMap<String,Object>();
		Column column= columnDAO.getColumnByCode(columnCode,null);
		if(column==null){
			throw new ColumnNotFoundException("栏目没找到");
		}
		
		//查询栏目的所有模块
		List<ModulesBO> modulesBOList= modulesDAO.findModules(columnCode,null);
		//查询栏目的所有模块的所有模块广告
		List<ModulesAdvertiseBO> ModulesAdvertiseBOList= modulesAdvertiseDAO.findModulesAdvertise(columnCode,null);
		//查询栏目的所有模块的所有模块商品数量
		int totalCount = modulesGoodsDAO.getModulesGoodsTotalCount(columnCode,cityCode,null); 
		
		//栏目的所有模块的所有模块商品为空 并且 城市代码不为0756(珠海)
		if( totalCount<=0 && !Constants.DEFAULT_CITY_CODE.equals(cityCode)){
			ResultVO resultVo = this.findColumnInfo(userId,columnCode,Constants.DEFAULT_CITY_CODE);
			return resultVo;
		}
		
		List<ModulesVO> list=new ArrayList<ModulesVO>();
		List<GoodsHistoryAEVO> goodsHistoryAEVOList=new ArrayList<GoodsHistoryAEVO>();
		for (ModulesBO modulesBO : modulesBOList) {
			ModulesVO modulesVO =new ModulesVO();
			BeanUtils.copyProperties(modulesBO, modulesVO);
			
			//拼装模块广告
			List<ModulesAdvertiseVO> modulesAdvertiseVOList=new ArrayList<ModulesAdvertiseVO>();
			for(int mi = 0;mi<ModulesAdvertiseBOList.size();){
				ModulesAdvertiseBO modulesAdvertiseBO = ModulesAdvertiseBOList.get(mi);
				if(modulesBO.getId().equals(modulesAdvertiseBO.getModulesId())){
					ModulesAdvertiseVO modulesAdvertiseVO=new ModulesAdvertiseVO();
					BeanUtils.copyProperties(modulesAdvertiseBO, modulesAdvertiseVO);
					modulesAdvertiseVOList.add(modulesAdvertiseVO);
					ModulesAdvertiseBOList.remove(mi);
				}
				mi++;
			}
			if(modulesAdvertiseVOList.size()>0){
				modulesVO.setModulesAdvertiseList(modulesAdvertiseVOList);
			}
				
			//拼装模块商品
			List<ModulesGoodsVO> modulesGoodsVOList=new ArrayList<ModulesGoodsVO>();
			List<ModulesGoodsBO>  modulesList = modulesGoodsDAO.findModulesGoodsBymodulesId(modulesVO.getId(),cityCode,null,0,20);
			for(int mi = 0;mi< modulesList.size();mi++){
				ModulesGoodsBO modulesGoodsBO = modulesList.get(mi);
				ModulesGoodsVO modulesGoodsVO=new ModulesGoodsVO();
				BeanUtils.copyProperties(modulesGoodsBO, modulesGoodsVO);
				modulesGoodsVOList.add(modulesGoodsVO);
				
				GoodsHistoryAEVO goodsHistoryAEVO=new GoodsHistoryAEVO();
				goodsHistoryAEVO.setKey(userId+"-"+modulesGoodsBO.getGoodsId()+"-"+GoodsHistoryType.EXPOSURE.toIntValue());
				goodsHistoryAEVO.setGoodsId(modulesGoodsBO.getGoodsId());
				goodsHistoryAEVO.setShopId(modulesGoodsBO.getShopId());
				goodsHistoryAEVO.setUserId(userId);
				goodsHistoryAEVO.setNumber(1);
				goodsHistoryAEVO.setCreatedTime(new Date());
				goodsHistoryAEVO.setType(GoodsHistoryType.EXPOSURE.toIntValue());
				goodsHistoryAEVOList.add(goodsHistoryAEVO);
			}
			if(modulesGoodsVOList.size()>0){
				modulesVO.setModulesGoodsList(modulesGoodsVOList);	
			}
			list.add(modulesVO);
		}
		
		if(StringUtils.isNotBlank(userId)){
			goodsHistoryService.add(goodsHistoryAEVOList);	
		}
		map.put("modules", list);
		map.put("cityCode", cityCode);
		result.setData(map);
		return result;
	}

//	@Override
//	  @Transactional
//	  public ResultVO findColumnInfo(String userId,String columnCode, String cityCode) {
//		long startTime=System.currentTimeMillis();
//		int cout = 0;
//		int gg = 0;
//		int sh = 0;
//	    ResultVO result=new ResultVO();
//	    Map<String,Object> map = new HashMap<String,Object>();
//	    Column column= columnDAO.getColumnByCode(columnCode,null);
//	    if(column==null){
//	      throw new ColumnNotFoundException("栏目没找到");
//	    }
//	    
//	    //查询栏目的所有模块
//	    List<ModulesBO> modulesBOList= modulesDAO.findModules(columnCode,null);
//	    //查询栏目的所有模块的所有模块广告
//	    List<ModulesAdvertiseBO> ModulesAdvertiseBOList= modulesAdvertiseDAO.findModulesAdvertise(columnCode,null);
//	    //查询栏目的所有模块的所有模块商品
//	    List<ModulesGoodsBO> ModulesGoodsBOList= modulesGoodsDAO.findModulesGoods(columnCode,cityCode,null); 
//	    
//	    //栏目的所有模块的所有模块商品为空 并且 城市代码不为0756(珠海)
//	    if( ModulesGoodsBOList.size()<=0 && !cityCode.equals(Constants.DEFAULT_CITY_CODE)){
//	      ResultVO resultVo = this.findColumnInfo(userId,columnCode,Constants.DEFAULT_CITY_CODE);
//	      return resultVo;
//	    }
//	    
//	    List<ModulesVO> list=new ArrayList<ModulesVO>();
//	    List<GoodsHistoryAEVO> goodsHistoryAEVOList=new ArrayList<GoodsHistoryAEVO>();
//	    for (ModulesBO modulesBO : modulesBOList) {
//	      ModulesVO modulesVO =new ModulesVO();
//	      BeanUtils.copyProperties(modulesBO, modulesVO);
//	      
//	      //拼装模块广告
//	      List<ModulesAdvertiseVO> modulesAdvertiseVOList=new ArrayList<ModulesAdvertiseVO>();
//	      for (ModulesAdvertiseBO modulesAdvertiseBO : ModulesAdvertiseBOList) {
//	        if(modulesBO.getId().equals(modulesAdvertiseBO.getModulesId())){
//	          ModulesAdvertiseVO modulesAdvertiseVO=new ModulesAdvertiseVO();
//	          BeanUtils.copyProperties(modulesAdvertiseBO, modulesAdvertiseVO);
//	          modulesAdvertiseVOList.add(modulesAdvertiseVO);
//	        }
//	        gg++;
//	        cout++;
//	      }
//	      if(modulesAdvertiseVOList.size()>0){
//	        modulesVO.setModulesAdvertiseList(modulesAdvertiseVOList);
//	      }
//	        
//	      //拼装模块商品
//	      List<ModulesGoodsVO> modulesGoodsVOList=new ArrayList<ModulesGoodsVO>();
//	      for (ModulesGoodsBO modulesGoodsBO : ModulesGoodsBOList) {
//	        if(modulesBO.getId().equals(modulesGoodsBO.getModulesId())){
//	          ModulesGoodsVO modulesGoodsVO=new ModulesGoodsVO();
//	          BeanUtils.copyProperties(modulesGoodsBO, modulesGoodsVO);
//	          modulesGoodsVOList.add(modulesGoodsVO);
//	          
//	          GoodsHistoryAEVO goodsHistoryAEVO=new GoodsHistoryAEVO();
//	          goodsHistoryAEVO.setKey(userId+"-"+modulesGoodsBO.getGoodsId()+"-"+GoodsHistoryType.EXPOSURE.toIntValue());
//	          goodsHistoryAEVO.setGoodsId(modulesGoodsBO.getGoodsId());
//	          goodsHistoryAEVO.setShopId(modulesGoodsBO.getShopId());
//	          goodsHistoryAEVO.setUserId(userId);
//	          goodsHistoryAEVO.setNumber(1);
//	          goodsHistoryAEVO.setCreatedTime(new Date());
//	          goodsHistoryAEVO.setType(GoodsHistoryType.EXPOSURE.toIntValue());
//	          goodsHistoryAEVOList.add(goodsHistoryAEVO);
//	        }
//	        sh++;
//	        cout++;
//	      }
//	      if(modulesGoodsVOList.size()>0){
//	        modulesVO.setModulesGoodsList(modulesGoodsVOList);  
//	      }
//	      
//	      list.add(modulesVO);
//	      cout++;
//	    }
//	    
//	    if(StringUtils.isNotBlank(userId)){
//	      goodsHistoryService.add(goodsHistoryAEVOList);  
//	    }
//	    map.put("modules", list);
//	    map.put("cityCode", cityCode);
//	    result.setData(map);
//		long endTime=System.currentTimeMillis();
//
//		System.out.println("程序运行时间： "+(endTime-startTime)+"ms,程序循环次数为:"+cout+",其中广告循环:"+gg+",商品循环:"+sh);
//	    return result;
//	  }
	
	@Override
	public ResultVO home(String columnCode) {
		ResultVO result=new ResultVO();
		Column column= columnDAO.getColumnByCode(columnCode,null);
		if(column==null){
			throw new ColumnNotFoundException("栏目没找到");
		}
		
		//查询栏目的所有模块的所有模块广告
		List<ModulesAdvertiseBO> ModulesAdvertiseBOList= modulesAdvertiseDAO.findModulesAdvertise(columnCode,null);
		
		Map<String, ModulesVO> modulesVOMap = new LinkedHashMap<String, ModulesVO>();
		
		for (ModulesAdvertiseBO bo : ModulesAdvertiseBOList) {
			ModulesVO modulesVO = modulesVOMap.get(bo.getModulesCode());
	        if (modulesVO==null) {
	        	modulesVO = new ModulesVO();
	        	BeanUtils.copyProperties(bo, modulesVO);
	        	modulesVO.setId(bo.getModulesId());
	        	modulesVO.setCode(bo.getModulesCode());
	        	modulesVO.setName(bo.getModulesName());
	        	List<ModulesAdvertiseVO> modulesAdvertiseVOList = new ArrayList<ModulesAdvertiseVO>();
	        	modulesVO.setModulesAdvertiseList(modulesAdvertiseVOList);
	        	modulesVOMap.put(modulesVO.getCode(),modulesVO);
	        }
	        
	        ModulesAdvertiseVO modulesAdvertiseVO=new ModulesAdvertiseVO();
	        BeanUtils.copyProperties(bo, modulesAdvertiseVO);
	        modulesVO.getModulesAdvertiseList().add(modulesAdvertiseVO);
	    }
		Collection<ModulesVO> data = modulesVOMap.values();
		result.setData(data);
		return result;
	}

	@Override
	public ListVO homeGoods(String userId, String columnCode, String modulesCode,String cityCode, Integer pageNumber,
			Integer maxPageRow) {
		Column column= columnDAO.getColumnByCode(columnCode,null);
		if(column==null){
			throw new ColumnNotFoundException("栏目没找到");
		}
		
		//查询栏目的所有模块的所有模块商品
		List<ModulesGoodsBO> ModulesGoodsBOList= modulesGoodsDAO.findModulesGoods(columnCode,cityCode,modulesCode,pageNumber,maxPageRow);
		
		Map<String, ModulesVO> modulesVOMap = new LinkedHashMap<String, ModulesVO>();
		List<GoodsHistoryAEVO> goodsHistoryAEVOList=new ArrayList<GoodsHistoryAEVO>();
		for (ModulesGoodsBO bo : ModulesGoodsBOList) {
			ModulesVO modulesVO = modulesVOMap.get(bo.getModulesCode());
	        if (modulesVO==null) {
	        	modulesVO = new ModulesVO();
	        	BeanUtils.copyProperties(bo, modulesVO);
	        	modulesVO.setId(bo.getModulesId());
	        	modulesVO.setCode(bo.getModulesCode());
	        	modulesVO.setName(bo.getModulesName());
	        	List<ModulesGoodsVO> modulesGoodsVOList = new ArrayList<ModulesGoodsVO>();
	        	modulesVO.setModulesGoodsList(modulesGoodsVOList);
	        	modulesVOMap.put(modulesVO.getCode(),modulesVO);
	        }
	        
	        ModulesGoodsVO modulesGoodsVO=new ModulesGoodsVO();
	        BeanUtils.copyProperties(bo, modulesGoodsVO);
	        modulesVO.getModulesGoodsList().add(modulesGoodsVO);
	        
	        GoodsHistoryAEVO goodsHistoryAEVO=new GoodsHistoryAEVO();
			goodsHistoryAEVO.setKey(userId+"-"+bo.getGoodsId()+"-"+GoodsHistoryType.EXPOSURE.toIntValue());
			goodsHistoryAEVO.setGoodsId(bo.getGoodsId());
			goodsHistoryAEVO.setShopId(bo.getShopId());
			goodsHistoryAEVO.setUserId(userId);
			goodsHistoryAEVO.setNumber(1);
			goodsHistoryAEVO.setCreatedTime(new Date());
			goodsHistoryAEVO.setType(GoodsHistoryType.EXPOSURE.toIntValue());
			goodsHistoryAEVOList.add(goodsHistoryAEVO);
	    }
		
		if(StringUtils.isNotBlank(userId)){
			goodsHistoryService.add(goodsHistoryAEVOList);	
		}
		
		Integer totalCount=modulesGoodsDAO.getTotalCount(columnCode, cityCode, modulesCode);
		
		ListVO listVO = new ListVO();
		listVO.setIndex(pageNumber);
		listVO.setCount(totalCount);
		listVO.setList(modulesVOMap.get(modulesCode));
		
		return listVO;
	}

	@Override
	public ListVO columnInfo(String userId, String columnCode, String cityCode, Integer pageNumber,
			Integer maxPageRow) {
		Column column= columnDAO.getColumnByCode(columnCode,null);
		if(column==null){
			throw new ColumnNotFoundException("栏目没找到");
		}
		
		//查询栏目的所有模块
		List<ModulesBO> modulesBOList= modulesDAO.findModules(columnCode,null);
		//查询栏目的所有模块的所有模块广告
		List<ModulesAdvertiseBO> ModulesAdvertiseBOList= modulesAdvertiseDAO.findModulesAdvertise(columnCode,null);
		//查询栏目的所有模块的所有模块商品
		List<ModulesGoodsBO> ModulesGoodsBOList= modulesGoodsDAO.findModulesGoods(columnCode,cityCode,null,pageNumber,maxPageRow);
		
		List<ModulesVO> list=new ArrayList<ModulesVO>();
		List<GoodsHistoryAEVO> goodsHistoryAEVOList=new ArrayList<GoodsHistoryAEVO>();
		for (ModulesBO modulesBO : modulesBOList) {
			ModulesVO modulesVO =new ModulesVO();
			BeanUtils.copyProperties(modulesBO, modulesVO);
			
			//拼装模块广告
			List<ModulesAdvertiseVO> modulesAdvertiseVOList=new ArrayList<ModulesAdvertiseVO>();
			for (ModulesAdvertiseBO modulesAdvertiseBO : ModulesAdvertiseBOList) {
				if(modulesBO.getId().equals(modulesAdvertiseBO.getModulesId())){
					ModulesAdvertiseVO modulesAdvertiseVO=new ModulesAdvertiseVO();
					BeanUtils.copyProperties(modulesAdvertiseBO, modulesAdvertiseVO);
					modulesAdvertiseVOList.add(modulesAdvertiseVO);
				}
			}
			if(modulesAdvertiseVOList.size()>0){
				modulesVO.setModulesAdvertiseList(modulesAdvertiseVOList);
			}
				
			//拼装模块商品
			List<ModulesGoodsVO> modulesGoodsVOList=new ArrayList<ModulesGoodsVO>();
			for (ModulesGoodsBO modulesGoodsBO : ModulesGoodsBOList) {
				if(modulesBO.getId().equals(modulesGoodsBO.getModulesId())){
					ModulesGoodsVO modulesGoodsVO=new ModulesGoodsVO();
					BeanUtils.copyProperties(modulesGoodsBO, modulesGoodsVO);
					modulesGoodsVOList.add(modulesGoodsVO);
					
					GoodsHistoryAEVO goodsHistoryAEVO=new GoodsHistoryAEVO();
					goodsHistoryAEVO.setKey(userId+"-"+modulesGoodsBO.getGoodsId()+"-"+GoodsHistoryType.EXPOSURE.toIntValue());
					goodsHistoryAEVO.setGoodsId(modulesGoodsBO.getGoodsId());
					goodsHistoryAEVO.setShopId(modulesGoodsBO.getShopId());
					goodsHistoryAEVO.setUserId(userId);
					goodsHistoryAEVO.setNumber(1);
					goodsHistoryAEVO.setCreatedTime(new Date());
					goodsHistoryAEVO.setType(GoodsHistoryType.EXPOSURE.toIntValue());
					goodsHistoryAEVOList.add(goodsHistoryAEVO);
				}
			}
			if(modulesGoodsVOList.size()>0){
				modulesVO.setModulesGoodsList(modulesGoodsVOList);	
			}
			
			list.add(modulesVO);
		}
		
		if(StringUtils.isNotBlank(userId)){
			goodsHistoryService.add(goodsHistoryAEVOList);	
		}
		
		Integer totalCount=modulesGoodsDAO.getTotalCount(columnCode, cityCode, null);
		
		ListVO listVO = new ListVO();
		listVO.setIndex(pageNumber);
		listVO.setCount(totalCount);
		listVO.setList(list);
		
		return listVO;
	}

	@Override
	public ResultVO home(String userId, String columnCode, String cityCode) {
		
		ResultVO result = new ResultVO();
		Column column= columnDAO.getColumnByCode(columnCode,null);
		if(column==null){
			throw new ColumnNotFoundException("栏目没找到");
		}
		
		Map<Integer, ModulesVO> modulesMap = new TreeMap<>();
		
		/*
		 * 	查出小程序首页的所有广告数据
		 */
		List<ModulesAdvertiseBO> advertiseBOList = modulesAdvertiseDAO.findByColumnCode(columnCode);
		for (ModulesAdvertiseBO advertiseBO : advertiseBOList) {
			ModulesVO modulesVO = modulesMap.get(advertiseBO.getModulesSort());
			if(modulesVO == null) {
				modulesVO = new ModulesVO();
				modulesVO.setCode(advertiseBO.getModulesCode());
				modulesVO.setName(advertiseBO.getModulesName());
				modulesVO.setModulesAdvertiseList(new ArrayList<ModulesAdvertiseVO>());
				modulesVO.setModulesGoodsList(new ArrayList<ModulesGoodsVO>());
				modulesMap.put(advertiseBO.getModulesSort(), modulesVO);
			}
			
			ModulesAdvertiseVO advertiseVO = new ModulesAdvertiseVO();
			BeanUtils.copyProperties(advertiseBO, advertiseVO);
			modulesVO.getModulesAdvertiseList().add(advertiseVO);
		}
		
		/*
		 * 	查出小程序首页的所有商品数据（每类商品前20条）
		 */
		List<ModulesGoodsBO> goodsBOList = modulesGoodsDAO.findByColumnCode(columnCode);
		for (ModulesGoodsBO goodsBO : goodsBOList) {
			ModulesVO modulesVO = modulesMap.get(goodsBO.getModulesSort());
			if(modulesVO == null) {
				modulesVO = new ModulesVO();
				modulesVO.setCode(goodsBO.getModulesCode());
				modulesVO.setName(goodsBO.getModulesName());
				modulesVO.setModulesAdvertiseList(new ArrayList<ModulesAdvertiseVO>());
				modulesVO.setModulesGoodsList(new ArrayList<ModulesGoodsVO>());
				modulesMap.put(goodsBO.getModulesSort(), modulesVO);
			}
			
			ModulesGoodsVO goodsVO = new ModulesGoodsVO();
			BeanUtils.copyProperties(goodsBO, goodsVO);
			modulesVO.getModulesGoodsList().add(goodsVO);
		}
		
		List<ModulesVO> list = new ArrayList<ModulesVO>();
		for (Integer key : modulesMap.keySet()) {
			ModulesVO modulesVO = modulesMap.get(key);
			list.add(modulesVO);
		}
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("modules", list);
		map.put("cityCode", cityCode);
		result.setData(map);
		return result;
	}
	
	@Override
	public ListVO homeGoods(String columnCode, String modulesCode, Integer pageNumber, Integer maxPageRow) {
		Column column= columnDAO.getColumnByCode(columnCode,null);
		if(column==null){
			throw new ColumnNotFoundException("栏目没找到");
		}
		
		ModulesVO modulesVO = new ModulesVO();
		modulesVO.setModulesGoodsList(new ArrayList<ModulesGoodsVO>());
		List<ModulesGoodsBO> goodsBOList = modulesGoodsDAO.findPaginationByCode(columnCode, modulesCode, pageNumber, maxPageRow);
		for (ModulesGoodsBO goodsBO : goodsBOList) {
			 ModulesGoodsVO goodsVO = new ModulesGoodsVO();
		     BeanUtils.copyProperties(goodsBO, goodsVO);
		     modulesVO.getModulesGoodsList().add(goodsVO);
		}
		
		int totalCount = modulesGoodsDAO.getPaginationTotalCount(columnCode, modulesCode);
		
		int size = modulesVO.getModulesGoodsList().size();
		if(size <= 0) {
			modulesVO = null;
		}
		
		ListVO listVO = new ListVO();
		listVO.setIndex(pageNumber);
		listVO.setCount(totalCount);
		listVO.setList(modulesVO);
		
		return listVO;
	}

	@Override
	public ListVO ShopModules(String locations, String coordsys, String columnCode, String modulesCode,
			int pageNumber, int maxPageRow) {
		//查询模块店铺
		List<ShopModulesBO> list = modulesShopsDAO.getShopByColumnCode(locations, coordsys, columnCode, modulesCode, pageNumber, maxPageRow);
		List<ShopModulesVO> shopModulesListVO  = new ArrayList<ShopModulesVO>();
		//查询广告
		List<AdvertiseBO> advertiselist = modulesShopsDAO.getAdvertiseByCode(modulesCode);
		ModulesShopVO modulesShopVO = new ModulesShopVO();
		List<AdvertiseVO> advertiseVOlist = new ArrayList<AdvertiseVO>();
		for(AdvertiseBO advertiseBO : advertiselist){
			AdvertiseVO advertiseVO = new AdvertiseVO();
			BeanUtils.copyProperties(advertiseBO, advertiseVO);
			advertiseVOlist.add(advertiseVO);
		}
		modulesShopVO.setAdvertise(advertiseVOlist);
		for(ShopModulesBO shopModulesBO : list){
			ShopModulesVO modulesVO = new ShopModulesVO();
			BeanUtils.copyProperties(shopModulesBO, modulesVO);
			modulesVO.setDistance(Format.decimal(shopModulesBO.getDistance()));
			List<GoodsBO> listStr = goodsDAO.getGoodsByShopId(shopModulesBO.getShopId());
			List<GoodsImagesVO> goodsImagesVOList = new ArrayList<>();
			for(GoodsBO goodsBO : listStr){
				GoodsImagesVO goodsImagesVO = new GoodsImagesVO();
				goodsImagesVO.setFileName(goodsBO.getFileName());
				goodsImagesVO.setId(goodsBO.getId());
				goodsImagesVO.setCode(goodsBO.getCode());
				goodsImagesVOList.add(goodsImagesVO);
			}
			modulesVO.setGoodsImg(goodsImagesVOList);
			shopModulesListVO.add(modulesVO);
			modulesShopVO.setShopModules(shopModulesListVO);
		}
		int totalCount = modulesShopsDAO.getShopByColumnCodeTotalCount(locations, coordsys, columnCode, modulesCode);
		ListVO listVO = new ListVO();
		listVO.setIndex(pageNumber);
		listVO.setCount(totalCount);
		listVO.setList(modulesShopVO);
		return listVO;
	}
}
